﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Google.Translates.Core;
using Google.Translates.Core.Entries;

namespace ml_test_google_trans
{
    public partial class TestForm : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write(DateTime.Now);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            DateTime startDate = DateTime.Now;
            var ss = new List<string>();
            ss.Add(txtSrc.Text);
            object reVal = new TranslatorByGoogleHttp().GetTranslations(ss, "", ddlTo.SelectedValue);
            if (reVal == null || !(reVal is TranslationResult)) return;
            txtTrg.Text = Server.HtmlDecode(((TranslationResult) reVal).Data.Translations[0].TranslatedText);
            lblMsg.Text = "Translation Uses Time : [" + (DateTime.Now - startDate).TotalMilliseconds + "]ms";
        }

        protected void btnDetect_Click(object sender, EventArgs e)
        {
            DateTime startDate = DateTime.Now;
            var reVal = new TranslatorByGoogleHttp().DetectTheSentence(txtSrc.Text);
            txtTrg.Text = Server.HtmlDecode(reVal);
            lblMsg.Text = "Detected Uses Time : [" + (DateTime.Now - startDate).TotalMilliseconds + "]ms";
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            var sb = new StringBuilder();
            foreach(var c in StringHelper.GetSentencesSplitsKey())
            {
                sb.Append(c + " -> ["+Convert.ToInt32(c)+"]<br />");
            }
            Response.Write(sb.ToString());
        }
    }
}